package com.agileboot.domain.system.tag.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.system.tag.db.SysTagEntity;
import com.agileboot.domain.system.tag.db.SysTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * 标签模型工厂
 * 仿照 NoticeModelFactory
 */
@Component
@RequiredArgsConstructor
public class TagModelFactory {

    @Qualifier("sysTagServiceImpl")
    private final SysTagService tagService;

    public TagModel loadById(Long tagId) {
        SysTagEntity byId = tagService.getById(tagId);

        if (byId == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, tagId, "系统标签");
        }

        return new TagModel(byId);
    }

    public TagModel create() {
        return new TagModel();
    }
}
